package com.music.music.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.music.common.log.annotation.Log;
import com.music.common.log.enums.BusinessType;
import com.music.common.security.annotation.RequiresPermissions;
import com.music.music.domain.MusicSinger;
import com.music.music.service.MusicSingerService;
import com.music.common.core.web.controller.BaseController;
import com.music.common.core.web.domain.AjaxResult;
import com.music.common.core.utils.poi.ExcelUtil;
import com.music.common.core.web.page.TableDataInfo;

/**
 * 音乐与歌手关联表Controller
 * 
 * @author ruoyi
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/musicsinger")
public class MusicSingerController extends BaseController
{
    @Resource
    private MusicSingerService musicSingerService;

    /**
     * 查询音乐与歌手关联表列表
     */
    @RequiresPermissions("music:musicsinger:list")
    @GetMapping("/list")
    public TableDataInfo list(MusicSinger musicSinger)
    {
        startPage();
        List<MusicSinger> list = musicSingerService.selectMusicSingerList(musicSinger);
        return getDataTable(list);
    }

    /**
     * 导出音乐与歌手关联表列表
     */
    @RequiresPermissions("music:musicsinger:export")
    @Log(title = "音乐与歌手关联表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MusicSinger musicSinger)
    {
        List<MusicSinger> list = musicSingerService.selectMusicSingerList(musicSinger);
        ExcelUtil<MusicSinger> util = new ExcelUtil<MusicSinger>(MusicSinger.class);
        util.exportExcel(response, list, "音乐与歌手关联表数据");
    }

    /**
     * 获取音乐与歌手关联表详细信息
     */
    @RequiresPermissions("music:musicsinger:query")
    @GetMapping(value = "/{musicId}")
    public AjaxResult getInfo(@PathVariable("musicId") Long musicId)
    {
        return success(musicSingerService.selectMusicSingerByMusicId(musicId));
    }

    /**
     * 新增音乐与歌手关联表
     */
    @RequiresPermissions("music:musicsinger:add")
    @Log(title = "音乐与歌手关联表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MusicSinger musicSinger)
    {
        return toAjax(musicSingerService.insertMusicSinger(musicSinger));
    }

    /**
     * 修改音乐与歌手关联表
     */
    @RequiresPermissions("music:musicsinger:edit")
    @Log(title = "音乐与歌手关联表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MusicSinger musicSinger)
    {
        return toAjax(musicSingerService.updateMusicSinger(musicSinger));
    }

    /**
     * 删除音乐与歌手关联表
     */
    @RequiresPermissions("music:musicsinger:remove")
    @Log(title = "音乐与歌手关联表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{musicIds}")
    public AjaxResult remove(@PathVariable Long[] musicIds)
    {
        return toAjax(musicSingerService.deleteMusicSingerByMusicIds(musicIds));
    }

    @RequestMapping("/feign/findSingerNameById")
    public String findSingerNameById(@RequestParam("musicId") Long musicId) {
        return musicSingerService.findSingerNameById(musicId);
    }

}
